<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Hello World</title>
    <script src="../vue.js"></script>
  </head>
  <body>
    <div id="root">
      <counter ref="one" @change="handleChange"></counter>
      <counter ref="two" @change="handleChange"></counter>
      <div>total:{{ totle }}</div>
    </div>
    <script>
      Vue.component('counter', {
        data: function() {
          return {
            number: 0
          }
        },
        template: '<div @click="handleClick">{{number}}</div>',
        methods: {
          handleClick() {
            this.number++
            this.$emit('change')
          }
        }
      })
      var vm = new Vue({
        el: '#root',
        data:{
          totle:0
        },
        methods: {
          handleChange() {
            this.totle = this.$refs.one.number + this.$refs.two.number
          }
        }
      })
    </script>
  </body>
</html>
